package subject_set.top101;

/**
 * @author haomin
 * @date 2022/11/28 22:51
 **/
public class BM7 {
    public class Solution {

        public ListNode EntryNodeOfLoop(ListNode pHead) {
            ListNode n1 = pHead;
            ListNode n2 = pHead;
            while(n1 != null && n1.next != null) {
                n1 = n1.next.next;
                n2 = n2.next;
                if(n1 == n2) break;
            }
            if(n1 == null || n1.next == null) return null;
            ListNode n3 = pHead;
            while(n3 != n1) {
                n3 = n3.next;
                n1 = n1.next;
            }
            return n3;
        }
    }
}